<script setup>
import { GetClothService } from '@/api/clothrequest'
import { ref } from 'vue'
import { useParms } from '@/stores'
defineProps({
  modelValue: {
    type: [Number, String]
  },
  width: {
    type: String
  }
})
const useparams = useParms()
const params = ref({
  factoryId: '', //产房号
  id: '', //车间号
  checkStartDate: '', //搜索开始时间
  checkEndDate: '', //搜索结束时间
  deviceCode: '', //机台号
  clothCode: '' //布匹编号
})
const emit = defineEmits(['update:modelValue'])
const clothList = ref([])
const getClothList = async () => {
  params.value.factoryId = useparams.params.factoryId
  params.value.id = useparams.params.id
  params.value.checkStartDate = useparams.params.checkStartDate
  params.value.checkStartDate = useparams.params.checkStartDate
  params.value.deviceCode = useparams.params.deviceCode
  params.value.clothCode = useparams.params.clothCode
  const res = await GetClothService(params.value)
  clothList.value = res.data.data
}
const changeCloth = ($event) => {
  useparams.params.clothCode = $event
  console.log(useparams.params)
}
getClothList()
</script>

<template>
  <!-- label 展示给用户看的，value 收集起来提交给后台的 -->
  <el-select
    :modelValue="modelValue"
    @update:modelValue="emit('update:modelValue', $event)"
    :style="{ width }"
    @change="changeCloth($event)"
    @click="getClothList()"
  >
    <el-option
      v-for="(item, index) in clothList"
      :key="index"
      :label="item.clothCode"
      :value="item.clothCode"
    ></el-option>
  </el-select>
</template>
